package com.kod.screen;

import java.util.Date;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.NinePatch;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
import com.badlogic.gdx.scenes.scene2d.ui.Window;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable;
import com.kod.BasicScreen;
import com.kod.activity.MainActivity;
import com.kod.activity.MainGame;

public class MainScreen extends BasicScreen {
	// Window window;
	TextureAtlas ta, btn;
	ImageButton ib;

	@Override
	public void onCreate() {
		// TODO Auto-generated method stub
		// window = WaitWindow.getInstance(font);
		// com.badlogic.gdx.scenes.scene2d.utils.Drawable

		ta = new TextureAtlas(Gdx.files.internal("1111.atlas"));
		btn = new TextureAtlas(Gdx.files.internal("btn.atlas"));
		ib = new ImageButton(new SpriteDrawable(
				btn.createSprite("BtS_SpeedStart")), new SpriteDrawable(
				btn.createSprite("BtN_SpeedStart")));
		ib.setX(450 * _scale);
		ib.setY(300 * _scale);
		ib.setSize(ib.getWidth() * _scale, ib.getHeight() * _scale);
		ib.addListener(new ClickListener() {

			@Override
			public void clicked(InputEvent event, float x, float y) {
				super.clicked(event, x, y);
				Screen sc = new GameScreen();
				MainActivity.game.list.add(sc);
				MainActivity.game.setScreen(sc);
			}

		});
		tmptime = new Date().getTime();
		stage.addActor(ib);
	}

	@Override
	public void onDispose() {
		// TODO Auto-generated method stub
		System.out.println("dispose");
	}

	int fps = 0;
	long tmptime, nowtime;
	String str = "main screen";

	@Override
	public void onRender(float f) {
		nowtime = new Date().getTime();
		if (nowtime >= tmptime + 1000) {
			str = "FPS:" + fps;
			fps = 0;
			tmptime = nowtime;
		} else {
			fps++;
		}

		// TODO Auto-generated method stub
		// System.out.println("onRender" + f);

		sb.begin();
		sb.draw(ta.findRegion("Bg_FirstScene"), 0, 0, _x, _y);
		sb.end();

		
	}

	@Override
	public void hander(String msg) {
		// TODO Auto-generated method stub

	}
}
